using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

using StillDesign.PhysX;

namespace Programonica.Igramonica.Physics
{
    public class TriggerReport : UserTriggerReport
    {
        private Dictionary<String, List<String>> hitComponents = new Dictionary<String, List<String>>(10);

        public Dictionary<String, List<String>> HitComponents
        {
            get { return hitComponents; }
            set { hitComponents = value; }
        }

        public TriggerReport(Scene scene) : base()
        {
            this.hitComponents = hitComponents;
        }

        public override void OnTrigger(Shape triggerShape, Shape otherShape, TriggerFlag status)
        {
            if (status == TriggerFlag.OnStay)
            {
                Actor triggerActor = triggerShape.Actor;
                
                if (!String.IsNullOrEmpty(triggerActor.Name))
                {
                    List<String> triggerOthers;

                    if (!hitComponents.TryGetValue(triggerActor.Name, out triggerOthers))
                    {
                        triggerOthers = new List<string>();

                        hitComponents.Add(triggerActor.Name, triggerOthers);
                    }

                    Actor otherActor = otherShape.Actor;

                    if (!String.IsNullOrEmpty(otherActor.Name))
                    {
                        if (!triggerOthers.Contains(otherActor.Name))
                        {
                            triggerOthers.Add(otherActor.Name);
                        }
                    }
                }
            }
        }
    }
}
